// app.ts
import common from "./common/index";
import api from "./api";
import {formatTime} from "./utils/util";

App<IAppOption>({
  towxml: require('/towxml/index'),
  globalData: {
    topic: {
      topic_id: '',
      topic_name: '',
    },
    statusBarHeight: 0,
    menuRight: 0,
    menuWidth: 0,
    navBarHeight: 0,
    user: {
      icon: '',
      uid: '',
      nickname: ''
    },
    vipInfo: {
      levelDesc: '',
      levelName: '',
      status: 0,
      endTime: '',
    },
    checkLoginPromise: null,
  },
  async onLaunch() {
    const systemInfo = wx.getSystemInfoSync(); //获取系统信息
    const menuInfo = wx.getMenuButtonBoundingClientRect(); // 获取胶囊按钮的信息
    console.log('menuInfo', menuInfo)
    // this.globalData.menuHeight = menuInfo.height; // 获取胶囊按钮的高
    this.globalData.menuWidth = menuInfo.width; // 获取胶囊按钮的宽
    this.globalData.statusBarHeight = systemInfo.statusBarHeight; // 获取状态栏的高
    this.globalData.menuRight = menuInfo.right; // 获取胶囊按钮的距离屏幕最右边的距离（此处用于设置导航栏左侧距离屏幕的距离）
    this.globalData.navBarHeight = (menuInfo.top - systemInfo.statusBarHeight) * 2 + menuInfo.height; // 计算出导航栏的高度
    // 启动时设置本地缓存的用户信息到全局globalData对象中
    const localUser = common.getLocalUser()
    common.setAppUserInfo(localUser, this.globalData)
    this.globalData.checkLoginPromise = new Promise(async (resolve, reject) => {
      const vipInfo = await common.getVipInfo()
      if (vipInfo) {
        common.setAppVipInfo(vipInfo, this.globalData)
        resolve(true)
      } else {
        reject()
      }
    })

  },

})